package sys.common.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.filter.OncePerRequestFilter;

import sys.common.Pubparameters;
import sys.module.sys.model.UserModel;

/**
 * <p>文件名称：BackURLFilter.java</p>
 * <p>文件描述：</p>
 * <p>版权所有： 版权所有(C)2000-2010</p>
 * <p>公    司： CWCA</p>
 * <p>内容摘要：TODO </p>
 * <p>其他说明： </p>
 * <p>完成日期：2014年2月15日</p>
 *
 * @author gao x 
 * @version 1.0 $Id: ican_code_comment.xml,v 1.3 2013/07/03 01:47:35 gaoxiang Exp $
 */
public class BackURLFilter extends OncePerRequestFilter {

	@Override
	protected void doFilterInternal(HttpServletRequest request,
			HttpServletResponse response, FilterChain filter)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		UserModel model = (UserModel) request.getSession().getAttribute(
				Pubparameters.SESSION_USER_INFO_SYS);
		String url = request.getRequestURI();
		if (model == null) {
			if (url != null && url.length() > 0) {
				if (url.contains("services")) {
					filter.doFilter(request, response);
					return;
				}
			}
			response.sendRedirect("/error.jsp");
			return;
		}
		filter.doFilter(request, response);
	}
}
